﻿using System;
using System.Collections;
using System.Text;

namespace SupervisedSpeakerRecognition
{
    /// <summary>
    /// 
    /// </summary>
    public class ExpectedResults
    {
        //************************  Private Fields  *******************************// 
        private String[] inputFileNames;
        private String[] fileNamesOnly;
        private String[] xValues;
        private ArrayList xValuesTemp;
        private ArrayList yValues;
        private int numberOfClusters;
        //************************  Public Properties  ****************************// 
        public ArrayList YValues
        {
            get { return yValues; }
            set { yValues = value; }
        }

        public String[] XValues
        {
            get { return xValues; }
            set { xValues = value; }
        }

        public String[] InputFileNames
        {
            get { return inputFileNames; }
            set { inputFileNames = value; }
        }

        public int NumberOfClusters
        {
            get { return numberOfClusters; }
            set { numberOfClusters = value; }
        }

        //************************  Public Methods  ****************************// 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="results"></param>
        public void claculateExpectedResults(ArrayList results)
        {
            clacXValues();
            YValues = new ArrayList();
            for (int i = 0; i < NumberOfClusters; i++)
            {
                YValues.Add(new double[XValues.Length]);
            }

            for (int i = 0; i < results.Count; i++)
            {
                int[] cluster = (int[])results[i];
                for (int j = 0; j < cluster.Length; j++)
                {
                    int temp = xValuesTemp.IndexOf(fileNamesOnly[cluster[j]]);
                    double[] cArr = (double[])YValues[i];
                    cArr[temp]++;
                }
            }

        }
        //************************  Private Methods  ****************************// 
        /// <summary>
        /// 
        /// </summary>
        private void clacXValues()
        {
            xValuesTemp = new ArrayList();
            fileNamesOnly = new String[inputFileNames.Length];
            for (int i = 0; i < inputFileNames.Length; i++)
            {
                fileNamesOnly[i] = getNameOnly(inputFileNames[i]);
                if (!xValuesTemp.Contains(fileNamesOnly[i]))
                    xValuesTemp.Add(fileNamesOnly[i]);
            }

            XValues = new String[xValuesTemp.Count];
            for (int i = 0; i < xValuesTemp.Count; i++)
            {
                XValues[i] = (String)xValuesTemp[i];
            }
        }
        /// <summary>
        /// execute to cat the number from the file name and leave only it
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private String getNameOnly(String input)
        {
            String temp = "";
            for (int i = 0; i < input.Length; i++)
            {
                if (!(input[i] >= '0' && input[i] <= '9'))
                    temp += input[i];
                else
                    return temp;
            }
            return temp;
        }
    }
}
